package com.joonhat.MonkeyFlash;


import net.rim.device.api.animation.AnimatedScalar;
import net.rim.device.api.animation.Animation;
import net.rim.device.api.animation.Animator;
import net.rim.device.api.animation.AnimatorListener;
import net.rim.device.api.system.Display;

import com.joonhat.MonkeyFlash.MyScreen.MyManager;

class AniEffect {
	private static Animator animator = new Animator(30);
	private static AnimatedScalar scalar;
	private static Animation ani;
	static{
		animator.setAnimatorListener(new AniListener()); 
	}

	static public void nextDirection(int direction) {
		if (direction == 1) {
			ani = animator.addAnimationTo(scalar,
					AnimatedScalar.ANIMATION_PROPERTY_SCALAR, 0,
					Constant.DEFAULT_EASING, Constant.DEFAULT_DURATION);
		} else {
			ani = animator.addAnimationTo(scalar,
					AnimatedScalar.ANIMATION_PROPERTY_SCALAR,
					-Display.getWidth(), Constant.DEFAULT_EASING,
					Constant.DEFAULT_DURATION);
		}
	}

	static public void begin(final long l) {
		ani.begin(l);
	}

	static public int getInt() {
		return scalar.getInt();
	}

	static public void setInt(int i) {
		if (scalar == null) {
			scalar = new AnimatedScalar(i);
		}
		scalar.setInt(i);
	}
	
	static class AniListener implements AnimatorListener{
		
		public void animatorUpdate() {
			MyManager.getIns().setManagerPosition(AniEffect.getInt(), 0);
			MyManager.getIns().invalidate();
		}
		
		public void animatorProcessing(boolean aniStart) {
			if (aniStart) {
				FlashHandler.getIns().setState(AnimateState.getInstance());
			} else {
				FlashHandler.getIns().setState(FlashHandler.getIns().getNextState());
			}
		}
	}
}